import os

from redis import Redis
_rd=Redis(os.environ.get('REDIS_HOST','10.36.172.28'),6379,db=3,decode_responses=True)


#字典
def exists(key):
    return _rd.exists(key)

def get(key):
    return _rd.get(key)


def mget(*args):
    return _rd.mget(args)

def set(name,value,time=None):
    if time:
        return _rd.setex(name,value,time)
    return _rd.set(name,value)

def mset(**kwargs):
    return _rd.mget(kwargs)

#自增1
def incr(key):
    return _rd.incr(key,amount=1)

#自减1
def decr(key):
    if not exists(key) or get(key<=0):
        return False
    else:
        return _rd.decr(key)

#Hash操作
def hset(name,key,value):
    return _rd.hset(name,key,value)

def hget(name,key):
    return _rd.hget(name,key)

def hgetall(name):
    return _rd.hgetall(name)

#输入多个
def hmset(name,dict_):
    return _rd.hmset(name,dict_)











